package com.example.geguo.custom;

/**
 * 作者： 13687
 * 创建日期：2018/6/24
 * 功能描述：
 */
public class ObservableCreate extends ObservableImp{
	private Command command;

	public ObservableCreate(Command command) {
		this.command = command;
	}

/**
 * caller Observerable#subscribe()
 * */
	@Override
	public void subscribeActual(Observer observer) {
//		将命令传递给观察者
		command.subscribe(new EmmitterAdapter(observer));
	}

	private class EmmitterAdapter implements Emmitter{

		public EmmitterAdapter(Observer observer) {
			this.observer = observer;
		}

		private Observer observer;

		@Override
		public void _next(Object element) {
			observer.onNext(element);
		}

		@Override
		public void _error(Throwable throwable) {
			observer.onErrror(throwable);
		}

		@Override
		public void _completed() {
			observer.onCompleted();
		}
	}
}
